<template>
	<view class="container">

		<view class="order-goods">
			<!-- <view class="goods">
				<view v-for="(item, index) in orderGoods" :key="index" class="item">
					<view class="img">
						<image :src="item.picUrl"></image>
					</view>
					<view class="info">
						<view class="t">
							<text class="name">{{item.goodsName}}</text>
						</view>
						<view class="t">
							<text class="attr">规格：{{item.specifications.toString()}}</text>
							<text class="number">x{{item.number}}</text>
						</view>
						<view class="price">￥{{item.price}}</view>
						<view class="btn active" v-if="handleOption.comment && (item.comment == 0)">
							<navigator :url="'../../commentPost/commentPost?orderId=' + item.orderId + '&&valueId=' + item.goodsId + '&type=0'">去评价</navigator>
						</view>
						<view class="btn active" v-if="handleOption.rebuy">
							<navigator :url="'../../goods/goods?id=' + item.goodsId">再次购买</navigator>
						</view>
					</view>
				</view>
			</view>

			<view class="order-bottom">
				<view class="total">
					<view class="t">
						<text class="label">商品合计：</text>
						<text class="txt">￥{{orderInfo.goodsPrice}}</text>
					</view>
					<view class="t">
						<text class="label">运费：</text>
						<text class="txt">￥{{orderInfo.freightPrice}}</text>
					</view>
					<view class="t">
						<text class="label">优惠减免：</text>
						<text class="txt">- ￥{{orderInfo.discountPrice}}</text>
					</view>
				</view>
				<view class="pay-fee">
					<text class="label">实付：</text>
					<text class="txt">￥{{orderInfo.actualPrice}}</text>
				</view>

			</view> -->

			<view class="order-header">
				<view class="order-header-code">订单商品</view>
				<view class="order-header-status">{{ orderInfo.orderStatusText }}</view>
			</view>
			<view class="goods">
				<view v-for="(item, index) in orderGoods" :key="index" class="item">
					<view class="img">
						<image :src="item.picUrl"></image>
					</view>
					<view class="info">
						<view class="info-title">{{ item.goodsName }}</view>
						<view class="info-counter">x {{ item.number }}</view>
						<view class="info-content">规格：{{ item.specifications.toString() }}</view>
						<view style="display:flex;align-items:center;justify-content:space-between;">
							<view class="info-price">￥{{ item.price }}</view>
							<!-- <view class="info-action">
								<view class="btn active" :data-index="item.id" @tap="refundOrder" v-if="showType != 1 && !item.handleOption.refund && item.goodsList.length > 1">退货查看</view>
								<view class="btn_yellow" v-if="item.handleOption.comment && gitem.comment == 0" :data-oid="gitem.orderId" :data-gid="gitem.goodsId" @tap.stop="toCommentPostPage">去评价</view>
								<view class="btn_yellow_border" v-if="item.handleOption.rebuy" :data-index="gitem.goodsId" @tap.stop="toGoodsDetailPage">再次购买</view>
								<view class="btn_yellow" v-if="gitem.refundId != null" :data-index="gitem.refundId" @tap.stop="toRefundDetailPage">退货查看</view>
							</view> -->
						</view>
					</view>
				</view>
			</view>
			<view class="order-footer">
				<view class="order-footer-price">实付:<text class="order-footer-price-count" style="font-size:35rpx;"><span style="font-size:24rpx;">￥</span>{{ orderInfo.actualPrice }}</text></view>
				<view class="order-footer-price">运费:<text class="order-footer-price-count" style="font-size:35rpx;"><span style="font-size:24rpx;">￥</span>{{ orderInfo.freightPrice }}</text></view>
				<view class="order-footer-price">减免:<text class="order-footer-price-count" style="font-size:35rpx;"><span style="font-size:24rpx;">￥</span>{{ orderInfo.discountPrice }}</text></view>
			</view>
		</view>

		<view class="order-info">

			<view class="order-header">
				<view class="order-header-code">订单信息</view>
			</view>
			<view class="t">
				<text class="lable">订单编号：</text>
				<text class="value">{{orderInfo.orderSn}}</text>
			</view>
			<view class="t">
				<text class="lable">下单时间：</text>
				<text class="value">{{orderInfo.addTime}}</text>
			</view>
			<view class="t">
				<text class="lable">收货人：</text>
				<text class="value">{{orderInfo.consignee}} {{orderInfo.mobile}}</text>
			</view>

			<view class="t">
				<text class="lable">收货地址：</text>
				<text class="value">{{orderInfo.address}}</text>
			</view>

			<view class="t">
				<text class="lable">订单备注：</text>
				<text class="value">{{orderInfo.message || '-'}}</text>
			</view>
			<!-- <view class="b">{{orderInfo.address}}</view> -->
		</view>
	</view>
</template>

<script>
const util = require("../../../utils/util.js");
const api = require("../../../config/api.js");

export default {
	data()
	{
		return {
			orderId: 0,
			orderInfo: {},
			orderGoods: [],
			flag: false,
			handleOption: {}
		};
	},

	components: {},
	props: {},
	onLoad: function (options)
	{
		// 页面初始化 options为页面跳转所带来的参数
		this.setData({
			orderId: options.id
		});
		this.getOrderDetail();
	},

	onPullDownRefresh()
	{
		uni.showNavigationBarLoading(); //在标题栏中显示加载

		this.getOrderDetail();
		uni.hideNavigationBarLoading(); //完成停止加载

		uni.stopPullDownRefresh(); //停止下拉刷新
	},

	onReady: function ()
	{// 页面渲染完成
	},
	onShow: function ()
	{// 页面显示
	},
	onHide: function ()
	{// 页面隐藏
	},
	onUnload: function ()
	{// 页面关闭
	},
	methods: {
		expandDetail: function ()
		{
			let that = this;
			this.setData({
				flag: !that.flag
			});
		},
		getOrderDetail: function ()
		{
			uni.showLoading({
				title: '加载中'
			});
			setTimeout(function ()
			{
				uni.hideLoading();
			}, 2000);
			let that = this;
			util.request(api.OrderDetail, {
				orderId: that.orderId
			}).then(function (res)
			{
				if (res.errno === 0)
				{
					console.log(res.data);
					that.setData({
						orderInfo: res.data.orderInfo,
						orderGoods: res.data.orderGoods,
						handleOption: res.data.orderInfo.handleOption
					});
				}

				uni.hideLoading();
			});
		},
		// “去付款”按钮点击效果
		payOrder: function ()
		{
			let that = this;

			let topic = uni.getStorageSync('topic')
			if (!topic)
			{
				console.log('topic id err')
				return
			}

			util.request(api.OrderPrepay, {
				topicId: topic.id,
				orderId: that.orderId
			}, 'POST').then(function (res)
			{
				if (res.errno === 0)
				{
					const payParam = res.data;
					uni.requestPayment({
						'timeStamp': payParam.timeStamp,
						'nonceStr': payParam.nonceStr,
						'package': payParam.packageValue,
						'signType': payParam.signType,
						'paySign': payParam.paySign,
						'success': function (res)
						{
							util.redirect('/pages/ucenter/order/order');
						},
						'fail': function (res)
						{
							util.showErrorToast('支付失败');
						},
						'complete': function (res)
						{
							console.log("支付过程结束");
						}
					});
				}
			});
		},
		// “取消订单”点击效果
		cancelOrder: function ()
		{
			let that = this;
			let orderInfo = that.orderInfo;
			uni.showModal({
				title: '',
				content: '确定要取消此订单？',
				success: function (res)
				{
					if (res.confirm)
					{
						util.request(api.OrderCancel, {
							orderId: orderInfo.id
						}, 'POST').then(function (res)
						{
							if (res.errno === 0)
							{
								uni.showToast({
									title: '取消订单成功'
								});
								util.redirect('/pages/ucenter/order/order');
							} else
							{
								util.showErrorToast(res.errmsg);
							}
						});
					}
				}
			});
		},
		// “取消订单并退款”点击效果
		refundOrder: function ()
		{
			let that = this;
			let orderInfo = that.orderInfo;
			uni.showModal({
				title: '',
				content: '确定要取消此订单？',
				success: function (res)
				{
					if (res.confirm)
					{
						util.request(api.OrderRefund, {
							orderId: orderInfo.id
						}, 'POST').then(function (res)
						{
							if (res.errno === 0)
							{
								uni.showToast({
									title: '取消订单成功'
								});
								util.redirect('/pages/ucenter/order/order');
							} else
							{
								util.showErrorToast(res.errmsg);
							}
						});
					}
				}
			});
		},
		// “删除”点击效果
		deleteOrder: function ()
		{
			let that = this;
			let orderInfo = that.orderInfo;
			uni.showModal({
				title: '',
				content: '确定要删除此订单？',
				success: function (res)
				{
					if (res.confirm)
					{
						util.request(api.OrderDelete, {
							orderId: orderInfo.id
						}, 'POST').then(function (res)
						{
							if (res.errno === 0)
							{
								uni.showToast({
									title: '删除订单成功'
								});
								util.redirect('/pages/ucenter/order/order');
							} else
							{
								util.showErrorToast(res.errmsg);
							}
						});
					}
				}
			});
		},
		// “确认收货”点击效果
		confirmOrder: function ()
		{
			let that = this;
			let orderInfo = that.orderInfo;
			uni.showModal({
				title: '',
				content: '确认收货？',
				success: function (res)
				{
					if (res.confirm)
					{
						util.request(api.OrderConfirm, {
							orderId: orderInfo.id
						}, 'POST').then(function (res)
						{
							if (res.errno === 0)
							{
								uni.showToast({
									title: '确认收货成功！'
								});
								util.redirect('/pages/ucenter/order/order');
							} else
							{
								util.showErrorToast(res.errmsg);
							}
						});
					}
				}
			});
		}
	}
};
</script>
<style>
page {
	height: 100%;
	width: 100%;
	background: #f4f4f4;
}

.order-info {
	background-color: #fff;
	margin: 0 0 20rpx;
	border-radius: 8rpx;
	overflow: hidden;
	padding: 0 0 30rpx;
}

.item-a {
	padding-left: 31.25rpx;
	height: 42.5rpx;
	padding-bottom: 12.5rpx;
	line-height: 30rpx;
	font-size: 30rpx;
	color: #666;
}

.item-b {
	padding-left: 31.25rpx;
	height: 29rpx;
	line-height: 29rpx;
	margin-top: 12.5rpx;
	margin-bottom: 41.5rpx;
	font-size: 30rpx;
	color: #666;
}

.item-c {
	margin-left: 31.25rpx;
	border-top: 1px solid #f4f4f4;
	height: 103rpx;
	line-height: 103rpx;
}

.item-c .l {
	float: left;
}

.item-c .r {
	height: 103rpx;
	float: right;
	display: flex;
	align-items: center;
	padding-right: 16rpx;
}

.item-c .r .btn {
	float: right;
}

.item-c .cost {
	color: #b4282d;
}

.item-c .btn {
	line-height: 66rpx;
	border-radius: 5rpx;
	text-align: center;
	margin: 0 15rpx;
	padding: 0 20rpx;
	height: 66rpx;
}

.item-c .btn.active {
	background: #b4282d;
	color: #fff;
}

.order-goods {
	background-color: #fff;
	overflow: hidden;
	margin-bottom: 10rpx;
}

.order-goods .h {
	height: 93.75rpx;
	line-height: 93.75rpx;
	margin-left: 31.25rpx;
	border-bottom: 1px solid #f4f4f4;
	padding-right: 31.25rpx;
}

.order-goods .h .label {
	float: left;
	font-size: 30rpx;
	color: #333;
}

.order-goods .h .status {
	float: right;
	font-size: 30rpx;
	color: #b4282d;
}

.order-goods .item {
	display: flex;
	align-items: top;
	margin-left: 31.25rpx;
	margin-bottom: 15.25rpx;
	padding-bottom: 15.25rpx;
	padding-right: 31.25rpx;
	border-bottom: 1px solid #f4f4f4;
}

.order-goods .item:last-child {
	border-bottom: none;
}

.order-goods .item .img {
	height: 140rpx;
	width: 140rpx;
	background: #f4f4f4;
}

.order-goods .item .img image {
	height: 140rpx;
	width: 140rpx;
}

.order-goods .item .info {
	flex: 1;
	min-height: 154rpx;
	margin-left: 30rpx;
}

.order-goods .item .t {
	margin-top: 14rpx;
	height: 45rpx;
	line-height: 45rpx;
	margin-bottom: 8.5rpx;
}

.order-goods .item .t .name {
	display: block;
	float: left;
	line-height: 16px;
	color: #333;
	font-size: 15px;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.order-goods .item .t .number {
	display: block;
	float: right;
	height: 29rpx;
	text-align: right;
	line-height: 29rpx;
	color: #333;
	font-size: 30rpx;
}

.order-goods .item .attr {
	height: 29rpx;
	line-height: 29rpx;
	color: #666;
	margin-bottom: 25rpx;
	font-size: 25rpx;
}

.order-goods .item .price {
	display: block;
	float: left;
	height: 30rpx;
	line-height: 30rpx;
	color: #333;
	font-size: 30rpx;
}

.order-goods .item .btn {
	height: 50rpx;
	line-height: 50rpx;
	border-radius: 40rpx;
	text-align: center;
	display: block;
	float: right;
	margin: 0 15rpx;
	padding: 0 20rpx;
}

.order-goods .item .btn.active {
	background: #ee9e09;
	color: #fff;
	border-radius: 40rpx;
}

.order-bottom {
	margin-top: 20rpx;
	padding-left: 31.25rpx;
	height: auto;
	overflow: hidden;
	background: #fff;
}

.order-info .address {
	height: 128rpx;
	padding-top: 25rpx;
}

.order-info .t {
	line-height: 55rpx;
	margin-bottom: 7.5rpx;
	display: flex;
	padding: 10rpx 30rpx;
}


.order-info .lable {
	display: block;
	width: 160rpx;
	line-height: 35rpx;
	font-size: 28rpx;
	flex-shrink: 0;
	flex-grow: 0;
	color: #898b8d;
}

.order-info .value {
	display: block;
	line-height: 35rpx;
	font-size: 30rpx;
	color: #666;
	flex-grow: 1;
	text-align: right;
}

.order-info .b {
	height: 50rpx;
	line-height: 40rpx;
	font-size: 30rpx;
	color: #999;
	padding-right: 10rpx;
	margin-bottom: 40rpx;
}

.order-bottom .total {
	height: 136rpx;
	padding-top: 20rpx;
	border-bottom: 1px solid #f4f4f4;
}

.order-bottom .total .t {
	height: 30rpx;
	line-height: 30rpx;
	margin-bottom: 7.5rpx;
}

.order-bottom .total .label {
	width: 250rpx;
	height: 35rpx;
	color: #999;
	line-height: 35rpx;
	font-size: 30rpx;
	float: left;
}

.order-bottom .total .txt {
	height: 35rpx;
	float: right;
	padding-right: 31.25rpx;
	line-height: 35rpx;
	font-size: 30rpx;
}

.order-bottom .pay-fee {
	height: 81rpx;
	line-height: 81rpx;
}

.order-bottom .pay-fee .label {
	width: 250rpx;
	color: #333;
	font-weight: bold;
	float: left;
}

.order-bottom .pay-fee .txt {
	float: right;
	padding-right: 31.25rpx;
	color: #b4282d;
}

.order-express {
	margin-top: 20rpx;
	width: 100%;
	height: 100rpx;
	background: #fff;
}

.order-express .title {
	float: left;
	margin-bottom: 20rpx;
	padding: 20rpx;
}

.order-express .ti {
	float: right;
	width: 52rpx;
	height: 52rpx;
	margin-right: 16rpx;
	margin-top: 28rpx;
}

.order-express .t {
	font-size: 29rpx;
	margin-left: 10.25rpx;
	color: #a78845;
}

.order-express .b {
	font-size: 29rpx;
	margin-left: 10.25rpx;
	color: #a78845;
}

.order-express .traces {
	padding: 17.5rpx;
	background: #fff;
	border-bottom: 1rpx solid #f1e6cdcc;
}

.order-express .trace {
	padding-bottom: 17.5rpx;
	padding-top: 17.5rpx;
	background: #fff;
}

.order-express .acceptTime {
	margin-top: 20rpx;
	margin-right: 40rpx;
	text-align: right;
	font-size: 26rpx;
}

.order-express .acceptStation {
	font-size: 26rpx;
}

.order-header {
	height: 92rpx;
	line-height: 92rpx;
	margin-left: 30rpx;
	border-bottom: 1px solid #f4f4f4;
	padding-right: 30rpx;
	display: -webkit-box;
	display: -webkit-flex;
	display: flex;
	-webkit-box-pack: justify;
	-webkit-justify-content: space-between;
	justify-content: space-between;
	margin-bottom: 20rpx;
}

.order-header-code {
	font-size: 26rpx;
	margin-bottom: 30rpx;
	font-size: 30rpx;
	font-weight: bold;
}

.order-header-status {
	float: right;
	color: #fd4d36;
	font-size: 24rpx;
}

.order-footer {
	height: 100rpx;
	box-sizing: border-box;
	margin: 0 30rpx;
	border-top: 1px solid #f4f4f4;
	font-size: 30rpx;
	color: #333;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.order-footer-price {
	color: #3c3e40;
	font-size: 24rpx;
}

.order-footer-price-count {
	color: #fd4d36;
	font-weight: bold;
}

.order-footer .btn_orange,
.order-footer .btn_orange_border {
	margin-left: 10rpx;
}

.order-footer-action {
	display: flex;
}

.info-action {
	display: flex;
}

.info-action .btn_yellow,
.info-action .btn_yellow_border {
	margin-left: 10rpx;
}

.info {
	flex: 1;
	min-height: 154rpx;
	margin-left: 30rpx;
	position: relative;
}

.info-title {
	color: #212223;
	font-size: 28rpx;

	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	margin-bottom: 10rpx;
	margin-right: 80rpx;
}

.info-content {
	color: #898b8d;
	display: flex;
	justify-content: space-between;
	margin-bottom: 15rpx;
}

.info-content text {
	color: #898b8d;
	font-size: 28rpx;
}

.info-price {
	color: #898b8d;
	font-size: 28rpx;
	transform: translateX(-5rpx);
}

.info-counter {
	position: absolute;
	right: 5rpx;
	top: 0;
}
</style>